import sys


a = input().split()
if len(a) != 3:
    print("Wrong input")
else:
    num_dict = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    
    try:
        digits = [num_dict[word] for word in a]
        number = digits[0] * 100 + digits[1] * 10 + digits[2]
        if number < 100 or number > 999:
            print("Wrong input")
        else:
            n = number
            lower = n
            upper = n
            def is_prime(num):
                if num <= 1:
                    return False
                if num == 2:
                    return True
                if num % 2 == 0:
                    return False
                for i in range(3, int(num**0.5) + 1, 2):
                    if num % i == 0:
                        return False
                return True
            found = False
            while not found:
                if lower > 1 and is_prime(lower):
                    print(lower)
                    found = True
                elif is_prime(upper):
                    print(upper)
                    found = True
                lower -= 1
                upper += 1
                
    except KeyError:
        print("Wrong input")
